/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.xinxi.dms.service;

import com.xinxi.dms.dao.AdminDao;
import com.xinxi.dms.po.Admin;
import java.util.List;

/**
 *
 * @author zhigu
 */
public class AdminServiceIMPL implements IAdminService {
    AdminDao adminDao = new AdminDao();
    @Override
    public Admin login(String name, String password) {
        String sql = "select * from admin where name = ? and password = ?";
        Object[] params={name,password};
        
        return adminDao.get(sql,Admin.class,params);
    }

    @Override
    public boolean into(Admin admin) {
        String sql = "insert into admin(name,password,phone,fullname,extent) values(?,123456,?,?,'管理员') ";
        Object[] params = {admin.getName(),admin.getPhone(),admin.getFullname()};
        return adminDao.update(sql, params);
    }

    @Override
    public List<Admin> findAll() {
        String sql = "select * from admin";
        Object[] params={};
        return adminDao.query(sql, Admin.class, params);
    }

    @Override
    public boolean update(Admin admin) {
//        String sql = "update room set money = ? ,remarks = ? where roomid = ?";
//        Object[] params = {room.getMoney(),room.getRemarks(),room.getRoomid()};
        String sql ="update admin set name = ?,phone = ? ,fullname = ? where id = ?";
        Object[] params={admin.getName(),admin.getPhone(),admin.getFullname(),admin.getId()};
        return adminDao.update(sql, params);
    }

    public boolean delete(Integer id) {
        String sql ="delete from admin where id = ?";
        Object[] params={id};
        return adminDao.update(sql, params);
    }
    
}
